home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15267 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  47 lines

  1. Newsgroups: comp.lang.c
  2. Path: netcom.com!smryan
  3. From: smryan@netcom.com (@#$%!?!)
  4. Subject: Re: Pointer to Functions and Calls thereof??
  5. Message-ID: <smryanDq0EEM.A9L@netcom.com>
  6. Organization: The Programmer formerly known as S M Ryan
  7. X-Newsreader: TIN [version 1.2 PL1]
  8. References: <Dq01Ft.Dqn@latcs1.lat.oz.au>
  9. Date: Wed, 17 Apr 1996 13:49:34 GMT
  10. Sender: smryan@netcom5.netcom.com
  11.  
  12. :     void    func1(void){naughty bits}
  13. :     void    func2(void){naughty bits}
  14.  
  15. :     void    main(void)
  16. :     {    void    *a[1];
  17.  
  18. :         a[1]=func1;
  19. :         a[2]=func2;
  20.  
  21.             These cast (void (*)(void)) to (void*) before
  22.             assigning to a.
  23.  
  24.             And the only valid subscript of a is [0].
  25.  
  26. :         (*a[1])();
  27.  
  28.             (*a[1]) has type (void) so appending a call list
  29.             doesn't make too much sense.
  30.  
  31. :     }
  32.  
  33. Perhaps
  34.         typedef void (*funcptr)(void);
  35.         funcptr a[2];
  36.  
  37.         a[0] = func1;
  38.         a[1] = func2;
  39.  
  40.         (*a[0])();
  41.  
  42. -- 
  43. The Queen who loves, the Queen of life,    | smryan@netcom.com  PO Box 1563
  44. the Queen who straits, the Queen of strife;|          Cupertino, California
  45. with gasp of death or gift of breath       | (xxx)xxx-xxxx            95015
  46. she brings the choice of birth or knife.   |         I don't use no smileys
  47.